<template>
  <div class="table-wrap">
    <div class="search_header">
      <div></div>
      <div class="search_header_right">
        <el-select
          placeholder="区（市）县"
          v-model="parameter.area"
          clearable
          @change="search"
        >
          <el-option
            v-for="item in projectAreaOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-input
          placeholder="请输入项目名称、业主单位"
          v-model="parameter.keyWord"
          clearable
          @keydown.enter.native="search"
        >
          <span
            @click="search"
            slot="suffix"
            style="display: inline-block"
          >
            <Icon
              title="搜索"
              name="sousuo"
              color="#A7ADB5"
              font-size="20"
            />
          </span>
        </el-input>
      </div>
    </div>
    <el-table
      :data="userList"
      :header-cell-style="{
        background: '#F2F6FB ',
        color: ' #6B767D'
      }"
      :row-class-name="tableRowClassName"
      v-loading="loading"
    >
      <el-table-column
        label="序号"
        show-overflow-tooltip
        width="80"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column
        label="区（市）县"
        prop="areaText"
        show-overflow-tooltip
      />
      <el-table-column
        label="批次名称"
        prop="batchName"
        show-overflow-tooltip
      />
      <el-table-column
        label="项目名称"
        prop="projectName"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        label="项目地址"
        prop="projectAddress"
        show-overflow-tooltip
      />
      <!-- <el-table-column
          label="建设规模"
          prop="createTime"
          show-overflow-tooltip
        /> -->
      <el-table-column
        label="组卷系统（受理时间）"
        prop="zjxtTime"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        label="更新时间"
        prop="updateTime"
        show-overflow-tooltip
      />
      <el-table-column
        label="状态"
        prop="statusText"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <!-- {{ scope.row.status == ? }} -->
          <span
            v-if="scope.row.status == '0'"
            style="color: red"
            >{{ scope.row.statusText }}</span
          >
          <span v-else>{{ scope.row.statusText }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        show-overflow-tooltip
        min-width="100"
      >
        <template v-slot="scope">
          <el-button
            type="text"
            style="color: #00baff; font-weight: 400"
            @click="handleDetail(3, scope, 'detail')"
            >查看</el-button
          >
          <el-button
            type="text"
            style="color: #00baff; font-weight: 400"
            @click="handleDetail(3, scope, 'edit')"
            v-has="'ExamData:edit'"
            >编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="table-pagination" v-if="total">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-size="parameter.pageSize"
        @current-change="pageChange"
        :total="total"
      >
      </el-pagination>
    </div>
    <shenhe ref="shenhe" @forceRender="getList"></shenhe>
  </div>
</template>

<script>
import { userQuery } from '@/api/user'
import { getProjectRecordList } from '@/api/projectRecord'
import { getZuJuanList } from '@/api/zujuan'
// import { mixin } from '@/views/wisdomConstruction/fileManagement/projectMethods'
import Icon from '@/components/icon'
// import { queryOptions } from '@/api/dict'
import { queryOptions } from '@/api/dict'
import shenhe from '@/views/wisdomConstruction/fileManagement/component/shenhe.vue'
import { isAdmin } from '@/utils/permission/index'
export default {
  name: 'index',
  components: {
    Icon,
    shenhe
  },
  // mixins: [mixin],
  data() {
    return {
      loading: false,
      userList: [],
      total: '',
      parameter: {
        area: '',
        keyword: '',
        pageIndex: 1,
        pageSize: 10
      },
      projectAreaOptions: [],
      total: '',
      canShenHe: null
    }
  },
  computed: {},
  async created() {
    await this.getAreaOptions()
    this.canShenHe = isAdmin()
  },
  mounted() {
    this.getList()
    this.canShenHe = isAdmin()
    console.log(isAdmin(), this.canShenHe)
  },
  methods: {
    handleDetail(index, scope, type) {
      this.$router.push({
        path: '/wisdomLand/SiteReportManagement/ExamData/formPage',
        query: {
          defaultIndex: index,
          pkid: scope?.row.pkid,
          type
        }
      })
    },
    getAreaOptions() {
      queryOptions('area').then((res) => {
        if (res.success) {
          this.projectAreaOptions = res.data.map((item) => {
            return {
              label: item.dictText,
              value: item.dictValue
            }
          })
        }
      })
    },
    search() {
      console.log(this.parameter, 'par')
      this.parameter.pageIndex = 1
      this.total = ''
      if (Array.isArray(this.parameter.deptId)) {
        this.parameter.deptId =
          this.parameter.deptId[
            this.parameter.deptId.length - 1
          ]
      }
      this.getList()
    },
    // pageChange
    pageChange(page) {
      this.parameter.pageIndex = page
      this.getList()
    },
    // 获取勘界列表
    getList() {
      this.loading = true
      getZuJuanList(this.parameter)
        .then((res) => {
          if (res.success) {
            this.userList = res.data.list
            this.total = res.data.count
          } else {
            this.$message.error(res.message)
          }
          this.loading = false
        })
        .catch((err) => (this.loading = false))
    },
    // tanble row
    tableRowClassName({ rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'light'
      } else {
        return ''
      }
    }
  }
}
</script>

<style scoped lang="scss">
@import '~@/assets/css/table.scss';
</style>
